<template>
  <form @submit.prevent>
    <slot></slot>
  </form>
</template>
<script>
export default {
  name: "zf-form",
  provide() {
    return {
      zfForm: this,
    };
  },
  props: {
    model: {
      type: Object,
      default: () => ({}),
    },
    rules: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {};
  },
  methods: {
    async validate(cb) {
      let children = this.$broadcast("zf-form-item");
      // console.log(children);
      try {
        let arrP = children.map((child) => {
          if (child.valitateForm && typeof child.valitateForm === "function") {
            return child.valitateForm();
          }
        });
        await Promise.all(arrP);
        cb(true);
      } catch (error) {
        console.log(error);
        cb(false, error);
      }
    },
    resetFields() {},
  },
};
</script>
<style></style>
